const express = require('express');
const router = express.Router();
const { pool } = require('../config/database');

// Create order
router.post('/', async (req, res) => {
  try {
    const { items, total, address } = req.body;
    
    res.json({
      success: true,
      message: 'Order created successfully',
      data: {
        orderId: 'ORDER_' + Date.now(),
        items,
        total,
        address,
        status: 'pending',
        createdAt: new Date().toISOString()
      }
    });
  } catch (error) {
    console.error('Create order error:', error);
    res.status(500).json({
      success: false,
      message: 'Failed to create order'
    });
  }
});

// Get order list
router.get('/', async (req, res) => {
  try {
    res.json({
      success: true,
      data: [
        {
          id: 'ORDER_1234567890',
          items: [{ name: 'Korean Fried Chicken', quantity: 2, price: 28.00 }],
          total: 56.00,
          status: 'completed',
          createdAt: '2024-01-01T12:00:00Z'
        }
      ]
    });
  } catch (error) {
    console.error('Get orders error:', error);
    res.status(500).json({
      success: false,
      message: 'Failed to get order list'
    });
  }
});

module.exports = router;